<?php

namespace app\admin\model;

use think\Model;

class UserModel extends Model
{
    protected $name = 'car_user'; //表名      默认类型
    protected $autoWriteTimestamp = true;
    protected $dateFormat = 'Y/m/d H:i:s';
    // 定义时间戳字段名
    protected $createTime = 'create_at';
    protected $updateTime = 'update_at';


    public function buy() {
        return $this->hasOne(PhotoBuy::class, 'userid', 'id');
    }

    public function report() {
        return $this->hasOne(PohtoReport::class, 'user_id', 'id');
    }

    /**
     * birthday修改位时间戳
     * @param $value
     */
    public function setBirthdayAttr($value)
    {
        return strtotime($value);
    }

    /**
     * birthday获取转成年月日
     * @param $value
     */
    public function getBirthdayAttr($value) {
        return date('Y-m-d', $value);
    }
}